import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import { IPropertyPaneConfiguration, PropertyPaneTextField } from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import { dynamicsService } from '../../services/services';
import * as strings from 'CreateFileWebPartStrings';
import ZhuhuaHt from './components/ZhuhuaHt';
import { IZhuhuaHtProps } from './components/IZhuhuaHtProps';
import './assets/style/base.scss';
import './assets/style/theme.scss';
import { sp } from '@pnp/sp/presets/all';
// import './assets/font/iconfont.css'
export interface ICreateFileWebPartProps {
  description: string;
  SiteLink: string;
}

export default class CreateFileWebPart extends BaseClientSideWebPart<ICreateFileWebPartProps> {
  public render(): void {
    const element: React.ReactElement<IZhuhuaHtProps> = React.createElement(ZhuhuaHt, {
      description: this.properties.description,
      username: this.context.pageContext.user.displayName,
      useremail: this.context.pageContext.user.email,
      sitelink: this.properties.SiteLink,
      absoluteUrl: this.context.pageContext.web.absoluteUrl,
      sitetitle: this.context.pageContext.web.title
    });
    ReactDom.render(element, this.domElement);
  }
  protected onInit(): Promise<void> {
    /* 隐藏相关导航栏 */

    // if (document.getElementById('spSiteHeader') != null) {
    //   document.getElementById('spSiteHeader').style.display = 'none';
    // }
    // if (document.getElementById('SuiteNavWrapper') != null) {
    //   document.getElementById('SuiteNavWrapper').style.display = 'none';
    // }
    // if (document.getElementById('spLeftNav') != null) {
    //   document.getElementById('spLeftNav').style.display = 'none';
    // }
    // if (document.getElementById('sp-appBar') != null) {
    //   document.getElementById('sp-appBar').style.display = 'none';
    // }
    // if (document.getElementById('spCommandBar') != null) {
    //   document.getElementById('spCommandBar').style.display = 'none';
    // }
    // if (document.getElementById('contentScrollRegion') != null) {
    //   document.getElementById('contentScrollRegion').style.overflowY = 'hidden';
    // } 

    

    dynamicsService.aadTokenProviderFactory = this.context.aadTokenProviderFactory;
    dynamicsService.resourceUri = `https://org49f3b3e8.api.crm5.dynamics.com`;
    return super.onInit().then(_ => {
      sp.setup({
        spfxContext: this.context
      });
      //   sp.setup({

      //     sp: {
      //       headers: {
      //         Accept: "application/json;odata=verbose",
      //         baseUrl: 'https://yuchentech.sharepoint.com/sites/zhuhuaHT'
      //       }
      //     }
      //   })
    });
  }

  protected onDispose(): void {
    ReactDom.unmountComponentAtNode(this.domElement);
  }

  protected get dataVersion(): Version {
    return Version.parse('1.0');
  }

  // protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
  //   return {
  //     pages: [
  //       {
  //         header: {
  //           description: strings.PropertyPaneDescription
  //         },
  //         groups: [
  //           {
  //             groupName: strings.BasicGroupName,
  //             groupFields: [
  //               PropertyPaneTextField('description', {
  //                 label: strings.DescriptionFieldLabel
  //               })
  //             ]
  //           }
  //         ]
  //       }
  //     ]
  //   };
  // }
}
